#使用已经编译好了的so文件直接拷贝到容器中
FROM php:7.2.29-fpm-alpine
#更新源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&apk update \
    #创建php扩展目录
    && docker-php-source extract \
    #安装必要依赖
    && apk add \
    autoconf  \
    gcc  \
    make  \
    libc-dev  \
    libxml2  \
    bzip2  \
    linux-headers  \
    libssh2  \
    libmcrypt  \
    unixodbc \
    sqlite  \
    libpng  \
    freetype  \
    libjpeg-turbo  \
    openssl  \
    g++  \
    rabbitmq-c  \
    unixodbc-dev  \
    sqlite-dev \
    rabbitmq-c-dev  \
    libssh2-dev  \
    libmcrypt-dev  \
    libjpeg-turbo-dev  \
    freetype-dev  \
    bzip2-dev \
    composer \
    git \
    #使用pecl安装扩展
    && pecl install  \
    redis  \
    amqp  \
    ssh2-1.2  \
    mongodb  \
    mcrypt  \
    igbinary  \
    && docker-php-ext-enable  \
    redis  \
    amqp  \
    ssh2  \
    mongodb  \
    mcrypt  \
    igbinary  \
    && docker-php-ext-install  \
    mysqli  \
    bz2  \
    zip  \
    shmop \
    #编译安装 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \
    && docker-php-ext-install gd \
    && docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
    && docker-php-ext-install pdo_odbc \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install pdo_sqlite \   
    && cd /usr/src/php/ext/sockets && /usr/local/bin/phpize \
    && ./configure --enable-sockets && make && make install \
    && docker-php-ext-enable sockets \
    && cd /usr/src/php/ext/opcache && /usr/local/bin/phpize \
    && ./configure --enable-opcache && make && make install \
    && docker-php-ext-enable opcache \
    #配置composer源
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    #删除临时文件等
    && apk del libc-dev unixodbc-dev sqlite-dev rabbitmq-c-dev libssh2-dev libmcrypt-dev libjpeg-turbo-dev freetype-dev bzip2-dev autoconf make gcc \
    && cd ~ && docker-php-source delete && rm -rf /tmp/pear

#swoole 和 grpc 编辑时间超长，直接拷贝文件so文件
COPY ./extensions/ /usr/local/lib/php/extensions/no-debug-non-zts-20170718/

RUN docker-php-ext-enable  \
    protobuf  \
    grpc  \
    swoole